<template>
	<view class="icons"  @click.stop="likeTap">
		<uni-icons :type="like? 'heart-filled':'heart'" size="20" color="#f07373"></uni-icons>
	</view>
</template>

<script>
	export default {
		name: "likes",
		props:{
			item:{
				type:Object,
				default(){
					return{}
				}
			}
		},
		data() {
			return {
				like: false
			};
		},
		watch:{
			item(newVal){
				this.like = this.item.is_like;
			}
		},
		created() {
			this.like = this.item.is_like;
		},
		methods:{
			likeTap(){
				console.log('已收藏');
				this.like = !this.like;
				this.setUpdateLike();
			},
			setUpdateLike(){
				uni.showLoading();
				this.$api.update_like({
					user_id:'607c062e5a4ad40001627d66',
					article_id:this.item._id
				}).then(res=>{
					uni.hideLoading();
					uni.showToast({
						title:this.like?'收藏成功':'取消收藏',
						icon:'none'
					});
					console.log('res',res);
				}).catch(()=>{
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style lang="scss">
	.icons {
		position: absolute;
		right: 0;
		top: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 20px;
		height: 20px;
	}
</style>
